<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<%@ include file="/pub/head_latest.inc"%>
    	<title></title>
	</head>
	<style type="text/css">
		img{
			width:16px !important;
		}
	</style>
	<script src="${baseURL}/js/calculate.js" type="text/javascript"></script>
	<script>
		 var calculate = new Calculate();
		/*  
		 calculate.setExpression("34+34*(3+1)");
 		 alert(calculate.calculateResult()); */
	</script>
	<body>
  		<!-- 搜索表单 -->
  		<c:if test="${fn:length(drawForm.views) > 0}">
	  		<div id="mainsearch" style="width:98%">
	    		<div class="searchbox">
	    			<!-- 此form表单ID必须为formsearch -->
		        	<form id="formsearch" name="formsearch" class="l-form" method="get">
				        <table cellpadding="0" cellspacing="1" class="l-table-edit" >
				            <tr>
				                <c:forEach var="o" items="${drawForm.views}" varStatus="idx">
	 			                	<td align="right" class="l-table-edit-td">${o.name}:</td>
	 			                	<c:if test="${o.displayType == 'text'}">
	 			                		<td align="left" class="l-table-edit-td" >
											<input type="text" id="${o.displayFieldName}" name="${o.displayFieldName}" value="${o.value}" ltype="text" class="field" value="" style="margin-left: 2px;width: 160px"/>
					                	</td> 
	 			                	</c:if>
	 			                	
	 			                	<c:if test="${o.displayType == 'select'}">
	 			                		<td align="left" class="l-table-edit-td" >
											<select type="" id="${o.displayFieldName}" name="${o.displayFieldName}" ltype="text"  value="${o.value}"  class="field" value="" style="margin-left: 2px;width: 160px">
												 <c:forEach var="d" items="${o.dicItem}" varStatus="idx">
												 	<option value="${d.id}" <c:if test="${d.selected}">selected</c:if>>${d.text}</option>
												 </c:forEach>
											</select>
					                	</td> 
	 			                	</c:if>
	 			                	
	 			                	<c:if test="${o.displayType == 'date'}">
	 			                		<td align="left" class="l-table-edit-td" >
	 											<input class="field"  type="text" ltype="date"  value="${o.value}"  name="${o.displayFieldName}_start" id="${o.displayFieldName}_start"/>
	 	 				                </td>
	 	 				                <td align="left" class="l-table-edit-td" >--</td>
	 			                		<td align="left" class="l-table-edit-td" >
	 											<input class="field"  type="text" ltype="date"  name="${o.displayFieldName}_end" id="${o.displayFieldName}_end"/>
	 	 				                </td> 
	 	 				                
	 	 				                <script>
	  	 				                	$("#${o.displayFieldName}_start").ligerDateEditor({
	 	 				                			    showTime: true,
	 	 				                			    label: '带时间',
	 	 				                			    labelWidth: 100,
	 	 				                			    labelAlign: 'left'
	 	 				                			});
	  	 				                	$("#${o.displayFieldName}_end").ligerDateEditor({
					                			    showTime: true,
					                			    label: '带时间',
					                			    labelWidth: 100,
					                			    labelAlign: 'left'
					                			});
	 	 				                </script>
	 			                	</c:if>
				                </c:forEach>
				              	<td align="left" class="l-table-edit-td">
									<button type="button" id="btnSearch" class="l-button l-button-submit"><i class="fa fa-search"></i> 搜索</button>
								</td>
								<td align="left" class="l-table-edit-td">
									<button type="reset" id="btnReset" class="l-button l-button-test" ><i class="fa fa-exchange"></i> 重置</button>
								</td>
				            </tr>
				        </table>
		       		</form>
				</div>
	  		</div>
  		</c:if>
 		<!-- 表格列表 -->
		<div id="maingrid" style="margin-top:10px;"></div>
		
		<!-- 报表打印区域 start -->
  		<iframe id="exportFrame" style="display:none" name="exportFrame" src="${baseURL}/report/view/reportview/defaultReport.do?csId=${drawForm.id}&rand=Math.rand()"></iframe>
  		 <script>
			function FF_Print(){
				var json = LG.bulidFilterParams($("#formsearch"));
  				exportFrame.window.FF_Print(json);
 			}
			
			function FF_ExportExcel(){
				var json = LG.bulidFilterParams($("#formsearch"));
 				exportFrame.window.FF_ExportExcel(json);
 			}
			
			function FF_ExportDoc(){
				var json = LG.bulidFilterParams($("#formsearch"));
 				exportFrame.window.FF_ExportDoc(json);
			}
			
			function FF_ExportPDF(){
				var json = LG.bulidFilterParams($("#formsearch"));
				exportFrame.window.FF_ExportPDF(json);
			}
		</script>
		<!-- 报表打印区域 end -->
		
		<!-- 钻取的配置 start -->
		<script>
 			function buildURLParams(json,url){
				var params = url;
 				if (url.indexOf("?") == -1) {
 					params += "?";
 				} else {
 					params += "&";
 				}
				var temp = "";
				for(var key in json){
					temp = key+"="+json[key]+"&";
					params += temp;
				}
				params = params.substring(0, params.length - 1);
				return encodeURI(encodeURI(params));
			}
		
			function FF_openDialog(data){
 				  $.ligerDialog({
					width:800,
					height:600,
					url:buildURLParams(data.json,data.url)
				});  
			}
			
			function FF_openTab(data){
				parent.f_addTab(data.linkName,data.linkName,buildURLParams(data.json,data.url));
			}
			
			function FF_openWindow(data){
				//设置弹窗大小
				var height = screen.height, // 用于计算弹出窗口的高度
					width  = screen.width - 80;  //用于计算弹出窗口的宽度
		  		window.open(buildURLParams(data.json,data.url),"newwindow","scrollbars=yes,height="+height+", width="+width+", top=0,left=60");
 			}
		</script>
		<!-- 钻取的配置 end -->
		 
  		<script type="text/javascript">
  		/*
  		 	解析获取最终替换数值的表达式
  		 	匹配{fieldName}
  		    可以实现 {num1}/{num2}*100%
  		*/
  		function dispart(expression,row){
		    var tempExpression = expression;
		    var regex = /\{(.+?)\}/ig;	
		    var r = "";
		    var temp = "";
			    while(r = regex.exec(expression)) {   
				  tempExpression = tempExpression.replace(r[0],row[r[1]] == undefined ?"":row[r[1]]);
		    }  
		    return tempExpression;
		}
  		
      	  //递归产生叶级列表结构
      	    function genChildColumn(columnObj){
       	    	var childrenColumns = [];
      	    	
      	    	if(columnObj.hasChidren){
      	    		for(var i = 0 ; i < columnObj.children.length ; i++){
      	      	    	var temp = {};
      	      	    	var tempObj = null;
      	    			tempObj = (columnObj.children)[i];
      	    			temp.display = tempObj.displayName;
      	    			temp.name = tempObj.fieldName;
      	    			temp.type = tempObj.type || "text";
      	    			
      	    			if (tempObj.hide) {
      	    				temp.hide = true;
      	    				temp.frozen = true;
      	    				temp.width = '0px';
      	    			}
      	    			
      	    		 	if(tempObj.link){
      	    		 		var linkForm = tempObj.linkForm;
      	    		 	  
      	    		 		temp.render = function(record, rowindex, value, column){
      	    		 			 var json = {};
      							 for(var i = 0 ; i < linkForm.linkParams.length ; i++){
     								 if(linkForm.linkParams[i].valueFieldName != null && linkForm.linkParams[i].valueFieldName!=''){
    									 json[linkForm.linkParams[i].fieldName] = record[linkForm.linkParams[i].valueFieldName];
    								 }else{
    									 json[linkForm.linkParams[i].fieldName] = linkForm.linkParams[i].value;
    								 }
    							 }
  	      	    		 		 var data = {
	     		      				    url:"${baseURL}/"+linkForm.linkURL+"" ,
	     		      					json:json,
	     		      					linkCode:""+linkForm.linkCode+"",
	     		      					linkName:""+linkForm.linkName+""
	     		      			};
	      	    		 		  if(value != undefined ){
	    	  		      			if(linkForm.openType == 0){//TAB
	    		 	      				return "<a href='javascript:FF_openTab("+JSON.stringify(data)+");'>"+value+"</a>";
	    			      			}else if(linkForm.openType == 1 ){// new window
	    		 	      				return "<a href='javascript:FF_openWindow("+JSON.stringify(data)+");'>"+value+"</a>";
	    			      			}else if(linkForm.openType == 2 ){// 弹出框
	    		 	      				return "<a href='javascript:FF_openDialog("+JSON.stringify(data)+");'>"+value+"</a>";
	    			      			}else{
	    		 	      				return "<a href='javascript:FF_openTab("+JSON.stringify(data)+");'>"+value+"</a>";
	    			      			}
	    		      			} 
	    	      				return value; //返回此单元格显示的HTML内容(一般根据value和row的内容进行组织)
       	    		 		}
      	    		 	}
      	    		 	
      	    		 	if(tempObj.useValueExpression){
      	    		 		temp.render = function(record, rowindex, value, column){
      	    		 			var valueExpression = dispart(tempObj.valueExpression,record);
      		      			 	calculate.setExpression(valueExpression);
      		      			 	return calculate.calculateResult(); 
      	    		 		}
      	    		 	}
      	    		 	
      	    		 	if(tempObj.hasChidren){
      	    		 		temp.columns = genChildColumn(tempObj);
      	    		 	}
      	    			childrenColumns[i] = temp;
          	    	}
       	    	}
       	    	return childrenColumns;
      	    }
      	  
	      	var columns = [];
	        <c:forEach var="o" items="${drawForm.results}" varStatus="idx">
  	      		var column_${idx.index} = {};
	      		column_${idx.index}.display = '${o.displayName}';
	      		column_${idx.index}.name = '${o.fieldName}';
	      		column_${idx.index}.type = '${o.type}' || 'text';
	      		
	      		<c:if test="${o.hide}">
	      			column_${idx.index}.hide = true;
      				column_${idx.index}.frozen = true;
      				column_${idx.index}.width = '0px';
	      		</c:if>
	      		 
	      		<c:if test="${o.hasChidren}">
	      			column_${idx.index}.columns = genChildColumn(${o.column});
	      		</c:if>
	      		
 	      		  <c:if test="${o.link || o.useValueExpression}">
 	      			column_${idx.index}.render = function (record, rowindex, value, column) {
	      			 <c:if test="${o.useValueExpression}">
	      			 	var valueExpression = dispart('${o.valueExpression}',record);
	      			 	calculate.setExpression(valueExpression);
	      			 	return calculate.calculateResult(); 
	      			 </c:if>
	      			 <c:if test="${o.link}">
	      				//this 这里指向grid， record 行数据 ,rowindex 行索引，value 当前的值，对应record[column.name],column 列信息
	      				var json = {};
	    	        	  <c:forEach var="op" items="${o.linkForm.linkParams}">
	    	        	  	<c:choose>
	    	        	  		<c:when test="${op.valueFieldName != null}">
	    	        	  			json.${op.fieldName} = record.${op.valueFieldName};
	    	        	  		</c:when>
	    	        	  		<c:otherwise>
	    	        	  			json.${op.fieldName} = "${op.value}";
	    	        	  		</c:otherwise>
	    	        	  	</c:choose>
						</c:forEach>  
		      			 var data = {
		      				    url:"${baseURL}${o.linkForm.linkURL}",
		      					json:json,
		      					linkCode:"${o.linkForm.linkCode}",
		      					linkName:"${o.linkForm.linkName}"
		      			};
		      			if(value != undefined ){
	  		      			if(${o.linkForm.openType == 0}){//TAB
		 	      				return "<a href='javascript:FF_openTab("+JSON.stringify(data)+");'>"+value+"</a>";
			      			}else if(${o.linkForm.openType == 1}){// new window
		 	      				return "<a href='javascript:FF_openWindow("+JSON.stringify(data)+");'>"+value+"</a>";
			      			}else if(${o.linkForm.openType == 2}){// 弹出框
		 	      				return "<a href='javascript:FF_openDialog("+JSON.stringify(data)+");'>"+value+"</a>";
			      			}else{
		 	      				return "<a href='javascript:FF_openTab("+JSON.stringify(data)+");'>"+value+"</a>";
			      			}
		      			}
	      				return value; //返回此单元格显示的HTML内容(一般根据value和row的内容进行组织)
	      			 </c:if>
	      			};
	      		</c:if>  
	      		columns[${idx.index}] = column_${idx.index};
	         </c:forEach> 
	         
	         
  	      	var grid = $("#maingrid").ligerGrid({ 
	      		columns: columns,
				dataAction: 'server',<c:if test="${drawForm.print || drawForm.pdf || drawForm.doc || drawForm.excel}">toolbar:{},</c:if>
	          	url: '${baseURL}/report/view/reportview/listJSON.do?csId=${drawForm.id}', sortName: 'code',
	          	width: '98%', height: '100%',heightDiff:-10, checkbox: false,
	          	pageParmName:"pageNo",pageSizeOptions:[${pageOptions}],pagesizeParmName:"perPageSize",
	          	rowHeight:23,rownumbers:true,isScroll:true,sortnameParmName:"sortName",
	          	sortorderParmName:"sortOrder",checkbox:false,pageSize: ${pageSize}
	      	});
  	      
  	      	var arr = [];
  	      	<c:if test="${drawForm.print}">
  	     		 arr.push({id : "print", name : "打印", clickEvent : FF_Print, icon:'/office/print.png'});
  	      	</c:if>
  	      	<c:if test="${drawForm.excel}">
    			 arr.push({id : "excel", name : "导出Excel", clickEvent : FF_ExportExcel,  icon:'/office/excel.png'});
     		</c:if>
     		<c:if test="${drawForm.pdf}">
  		 		arr.push({id : "pdf", name : "导出Word", clickEvent : FF_ExportDoc,  icon:'/office/word.png'});
   			</c:if>
   			<c:if test="${drawForm.doc}">
		 		arr.push({id : "doc", name : "导出PDF", clickEvent : FF_ExportPDF, icon:'/office/pdf.png'});
			</c:if>
  	      	
  	      	if(arr.length > 0){
  	   	      	LG.createToolbarButton(grid, arr);
  	      	}
 
	      	$("#formsearch").ligerForm();
		  	//搜索事件
	      	$("#btnSearch").click(function(e){
	    		var json = LG.bulidFilterParams($("#formsearch"));
	        	grid.set('parms', json);
	            //采用原来的请求地址，带上参数加载数据
			  	grid.loadData();
	      	});
		  	
	      	$("#btnSearch").click();
		  
	 	   	//重置事件
	      	$("#btnReset").click(function(e){
				grid.set('parms', null);
	            //采用原来的请求地址，带上参数加载数据
			   	grid.loadData();
	     	});
	  	  
	      	//一个重新加载数据方法，该方法主要作为外部框架调用使用
	      	function FF_Reload(){
				grid.loadData();
	      	}
	      	
	     	// 搜索框绑定回车事件
	      	$("#mainsearch").bind("keydown",function(e){
		      	　　// 兼容FF和IE和Opera
		      	　　var theEvent = e || window.event;
		      	　　var code = theEvent.keyCode || theEvent.which || theEvent.charCode;
		      	　　if (code == 13) {
		      	　　	 //回车执行查询
		      	　　	 $("#btnSearch").click();
			      	 return false;
		      	　　}
	      	});
		</script>
	</body>
</html>
